package Day09方法重载_参数传递;

//设计方法 获取数组中最大值

public class Demo01 {
    public static void main(String[] args) {

        int[] arr = {1,2,3,4,5}; //地址0x111
        int max = max(arr);
        System.out.println("max=" + max);

        int[] arr1 = {11,22,33,44,55}; //地址0x222
        int max1 = max(arr1);
        System.out.println("max2=" + max1);
    }

    public static int max(int[] arr){ //地址0x111/0x222 带入新数组,新数组指向原数组arr
        int max = arr[0]; //max保存最大值
        // 遍历数组
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] > max){
                max = arr[i];
            }
        }
        return max;
    }
}
